package io.renren.softpark.controller;

import com.yunlong.common.utils.PageUtils;
import com.yunlong.common.utils.R;
import io.renren.softpark.entity.RecordEntity;
import io.renren.softpark.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @Author: Cui
 * @Date: 2020/8/23
 * @Description:
 */
@RestController
@RequestMapping("generator/record")
public class RecordController {

    @Autowired
    RecordService recordService;
    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("generator:sort:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = recordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{sortId}")
//    @RequiresPermissions("generator:sort:info")
    public R info(@PathVariable("sortId") Integer sortId){
        RecordEntity record = recordService.getById(sortId);

        return R.ok().put("sort", record);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("generator:sort:save")
    public R save(@RequestBody RecordEntity record){
        recordService.save(record);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("generator:sort:update")
    public R update(@RequestBody RecordEntity record){
        recordService.updateById(record);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("generator:sort:delete")
    public R delete(@RequestBody String[] sortIds){
        recordService.removeByIds(Arrays.asList(sortIds));

        return R.ok();
    }
}
